<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules" label-width="80px">

			<el-row>
				<el-col :span="10">
					<el-form-item label="客户姓名" prop="customerName">
						<el-input v-model="form.customerName" :disabled="true"></el-input>
					</el-form-item>
				</el-col>

				<el-col :span="10">
					<el-form-item label="护理项目" prop="nursingProject">
						<el-input v-model="form.nursingProject"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
<el-row>
				<el-col :span="10">
					<el-form-item label="购买数量" prop="buyNum">
						<el-input v-model="form.buyNum" @blur="buyInput()"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="10">
					<el-form-item label="总数量" prop="allNum">
						<el-input v-model="form.allNum" :disabled="true" ></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col :span="10">
					<el-form-item label="备注">
						<el-input v-model="form.remarks"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row></el-row>

			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import axios from '@/utils/axiosutils.js';
	export default {
		name: 'careAdd',
		props: ['editid'],
		components: {},
		data() {
			return {
				form: {
					customerName: '',
					nursingProject: '',
					buyNum: '',
					remarks: '',
					allNum: ''
				},
				rules: {
					nursingProject: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					buyNum: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
				},
			};
		},
		created() {
			if (this.editid) {
				// 如果是修改 用户名输入框禁用
				this.isupdate = true;
				axios.get(
					'/carePurchased/getById',
					response => {
						console.log(response)
						this.form.careId = this.editid;
						this.form.customerName = response.obj.customerName;
						this.form.nursingProject = response.obj.nursingProject;
						// this.form.buyNum = response.obj.buyNum;
						this.form.allNum = response.obj.allNum;
						 this.form.remarks = response.obj.remarks;
					}, {
						careId: this.editid
					}
				);
			}
		},
		methods: {
			save: function() {
				if (this.editid) {
					axios.post(
						'/carePurchased/update',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				} else {
					axios.post(
						'/carePurchased/add',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getdata');
						},
						this.form
					);
				}
			},
			buyInput(){
				if(this.form.allNum==null){
					this.form.allNum=this.form.buyNum
				}else{
					this.form.allNum=parseInt(this.form.allNum)+parseInt(this.form.buyNum);
			    }
			}

		}

	};
</script>

<style scoped>
	.el-row{
		
	}
</style>
